package com.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.User;
import com.service.UserService;

@Controller
public class UserController {
	@Autowired
	private UserService manservice;
	
	
    @RequestMapping(value="login.action")
	public String login(String name,String password,Model model,HttpSession session) {
		System.out.println("进入登陆管理");
		System.out.println(name+password);
    	User man=manservice.findUser(name, password);
		
    	//判断用户是否存在
		if(man!=null) {
			session.setAttribute("Users", man);
			
			return "redirect:./list.action?uid="+man.getId();
		}
		model.addAttribute("msg","账户名或密码错误");
		return "login";
	}
	
   
	
    @RequestMapping(value="logout.action")
    public String logout(HttpSession session) {
 	   System.out.println("退出登陆");
 	   session.invalidate();
 	   
 	   return "login";
 	   
    }
}
